package com.topboya.officeuser.controller;

import com.topboya.officeuser.entity.Office;
import com.topboya.officeuser.entity.User;
import com.topboya.officeuser.service.UserService;
import com.topboya.officeuser.utils.IfUser;
import com.topboya.officeuser.utils.Result;
import com.topboya.officeuser.utils.UtilTools;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @className UserController
 * @Author xiaxin
 * @Date 2020/8/8 18:38
 * @Version 1.0
 **/
@Api(tags = "这是一个user控制类",value = "useriso-8859-1")
@RestController
public class UserController {

    @Autowired
    UserService userService;
    @ApiOperation(value = "新增用户信息",notes = "新增用户的")
    @PostMapping("user")
    public Result saveUser(@RequestBody User user){

        user.setId(UtilTools.getNum19());
        int i = userService.insertUser(user);
        if(i<=0){
            Result.error();
        }
        return Result.ok();
    }


    @ApiResponses({
            @ApiResponse(code=400,message="请求参数没填好"),
            @ApiResponse(code=404,message="请求路径没有或页面跳转路径不对")
    })
    @ApiOperation(value = "分页并条件查询员工信息")
    @GetMapping("user/{current}/{size}")
    public Result queryUser(@RequestBody  User user, @PathVariable Integer current, @PathVariable Integer size){
        Map<String, Object> mapUser = new HashMap<>();
        mapUser.put("current",current);
        mapUser.put("size",size);
        List<User> userList = userService.queryAllUserByIfAndPage(mapUser,user);
        return Result.ok().data("userList",userList);
    }
}
